﻿Public NotInheritable Class VirtualController
    Implements IController

    Private m_leftStickPos As PointF
    Private m_rightStickPos As PointF
    Private m_parent As Form

    Public Sub New(ByVal parent As Form)
        m_leftStickPos = New PointF(0.5, 0.5)
        m_rightStickPos = New PointF(0.5, 0.5)

        m_parent = parent
    End Sub

    Public Function GetLeftStickPos() As System.Drawing.PointF Implements IController.GetLeftStickPos
        Return m_leftStickPos
    End Function

    Public Function GetRightStickPos() As System.Drawing.PointF Implements IController.GetRightStickPos
        Return m_rightStickPos
    End Function

    Public Sub SetLeftStickPos(ByVal pos As PointF)
        m_leftStickPos = pos
    End Sub

    Public Sub SetRightStickPos(ByVal pos As PointF)
        m_rightStickPos = pos
    End Sub

    Public ReadOnly Property Parent() As frmVirtualController
        Get
            Return m_parent
        End Get
    End Property

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: free other state (managed objects).

                If Not m_parent Is Nothing Then
                    Try
                        m_parent.Hide()
                        m_parent.Close()
                        m_parent.Dispose()
                    Catch ex As Exception

                    End Try
                    m_parent = Nothing
                End If
            End If

            ' TODO: free your own state (unmanaged objects).
            ' TODO: set large fields to null.
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

    Public Function IsConnected() As Boolean Implements IController.IsConnected
        Return True
    End Function
End Class
